package com.zhuandaonet.springjpa.service;

import com.zhuandaonet.common.exception.ServiceException;
import com.zhuandaonet.springjpa.entity.IEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.io.Serializable;
import java.util.List;

public interface IService<T extends IEntity,ID extends Serializable> {
    /**
     * 添加或者保存实体，需要提交事务才生效
     * @param t
     * @return
     * @throws SecurityException
     */
    T save(T t) throws SecurityException;

    /**
     * 保存实体，直接保存到数据库中
     * @param t
     * @return
     * @throws ServiceException
     */
    T saveAndFush(T t) throws ServiceException;

    /**
     * 根据ID获取实体
     * @param id
     * @return
     * @throws ServiceException
     */
    T getOneById(ID id) throws ServiceException;

    /**
     * 根据ID删除一个实体
     * @param id
     * @throws ServiceException
     */
    void delete(ID id) throws ServiceException;

    /**
     * 根据ID的集合删除实体
     * @param ids
     * @throws ServiceException
     */
    void delete(String[] ids) throws ServiceException;

    /**
     * 根据实体的集合删除实体
     * @param ts
     * @throws ServiceException
     */
    void delete(List<T> ts) throws ServiceException;

    /**
     * 查询所有
     * @return List
     * @throws ServiceException
     */
    List<T> findAll() throws ServiceException;

    /**
     * 分页查询所有
     * @param pageable
     * @return
     * @throws ServiceException
     */
    Page<T> findAll(Pageable pageable) throws ServiceException;

    /**
     * 根据条件分页查询所有
     * @param t
     * @param pageable
     * @return
     * @throws ServiceException
     */
    Page<T> findAll(T t,Pageable pageable) throws ServiceException;

    /**
     * 判断实体存不存在
     * @param t
     * @return
     * @throws ServiceException
     */
    Boolean exist(T t) throws ServiceException;

    /**
     * 根据ID判断实体是否存在
     * @param id
     * @return
     * @throws ServiceException
     */
    Boolean exist(ID id) throws ServiceException;

    /**
     * 根据条件统计实体数量
     * @param t
     * @return
     * @throws ServiceException
     */
    Long count(T t) throws ServiceException;

    /**
     * 统计
     * @return
     * @throws ServiceException
     */
    Long count() throws ServiceException;
}
